//package com.zmn.plat.task.job.channel;
//
//import com.github.ltsopensource.core.domain.Action;
//import com.github.ltsopensource.core.domain.Job;
//import com.github.ltsopensource.spring.tasktracker.JobRunnerItem;
//import com.github.ltsopensource.spring.tasktracker.LTS;
//import com.github.ltsopensource.tasktracker.Result;
//import com.zmn.common.constant.StatusConsts;
//import com.zmn.common.dto2.ResponseDTO;
//import com.zmn.common.utils.collection.CollectionUtil;
//import com.zmn.common.utils.date.DateUtil;
//import com.zmn.common.utils.number.NumberUtil;
//import com.zmn.manager.lts.interfaces.task.TaskManager;
//import com.zmn.plat.manager.utils.TaskConsts;
//import com.zmn.plat.model.entity.channel.brand.ratio.ChannelBrandRatio;
//import com.zmn.plat.model.entity.channel.brand.ratio.ChannelBrandRatioQuery;
//import com.zmn.plat.services.interfaces.channel.brand.ratio.ChannelBrandRatioService;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//
//import javax.annotation.PostConstruct;
//import javax.annotation.Resource;
//import java.util.ArrayList;
//import java.util.List;
//import java.util.Objects;
//
///**
// * 描述：渠道品牌待生效系数定时任务
// *
// * @author linfeng
// * @version v1.0
// * @since 2020/09/03 11:16
// */
//@LTS
//public class ChannelBrandRatioJob {
//
//    private Logger logger = LoggerFactory.getLogger(ChannelBrandRatioJob.class);
//
//    @Resource
//    TaskManager taskManager;
//    @Resource
//    ChannelBrandRatioService channelBrandRatioService;
//
//    /**
//     * 描述: 渠道品牌待生效系数任务提交
//     *
//     * @author linfeng
//     * @since 2020/09/03 14:23
//     */
//    @PostConstruct
//    void init() {
//        Job job = new Job();
//        job.setTaskId(TaskConsts.TASK_ID_CHANNEL_BRAND_RATIO);
//        job.setParam(TaskManager.SHARD_FIELD, TaskConsts.TASK_ID_CHANNEL_BRAND_RATIO);
//        job.setCronExpression("0 0/0 0 * * ?");
//        job.setReplaceOnExist(true);
//        ResponseDTO<String> result = taskManager.submitTask2(job);
//        if (!result.isSuccess() || !Objects.equals(result.getStatus(), StatusConsts.STATUS_SUCCESS)) {
//            logger.error("#ChannelBrandRatio# job submit fail...");
//        }
//    }
//
//    /**
//     * 执行渠道待生效品牌系数JOB
//     *
//     * @param job the job
//     * @return result
//     */
//    @JobRunnerItem(shardValue = TaskConsts.TASK_ID_CHANNEL_BRAND_RATIO)
//    public Result runChannelBrandRatioJob(Job job) {
//
//        logger.debug("#job#ChannelBrandRatio#start running...");
//
//        ChannelBrandRatioQuery query = new ChannelBrandRatioQuery();
//        query.setEffectiveDate(DateUtil.getDateStart(DateUtil.getNow()));
//        List<ChannelBrandRatio> channelBrandRatios = channelBrandRatioService.listByQuery(query);
//
//        if (CollectionUtil.isNullOrEmpty(channelBrandRatios)) {
//            return new Result(Action.EXECUTE_SUCCESS, "当天没有需要生效的渠道品牌系数");
//        }
//
//        ChannelBrandRatio channelBrandRatio;
//        List<ChannelBrandRatio> updateChannelBrandRatioList = new ArrayList<>(channelBrandRatios.size());
//        for (int i = 0; i < channelBrandRatios.size(); i++) {
//            channelBrandRatio = channelBrandRatios.get(i);
//            ChannelBrandRatio updateData = new ChannelBrandRatio();
//            if (NumberUtil.isNullOrZero(channelBrandRatio.getRatioId())) {
//                continue;
//            }
//
//            updateData.setRatioId(channelBrandRatio.getRatioId());
//            updateData.setRatio(channelBrandRatio.getToBeEffectiveRatio());
//            updateData.setUpdater("定时任务");
//            updateData.setUpdateTime(DateUtil.getNow());
//
//            updateChannelBrandRatioList.add(updateData);
//        }
//
//        if (CollectionUtil.isNullOrEmpty(updateChannelBrandRatioList)) {
//            return new Result(Action.EXECUTE_SUCCESS, "当天没有需要生效的渠道品牌系数");
//        }
//
//        Integer count = channelBrandRatioService.updateRatioByKeyBatch(updateChannelBrandRatioList);
//
//        logger.debug("#job#ChannelBrandRatio#end running... update count :" + count);
//        return new Result(Action.EXECUTE_SUCCESS, "渠道品牌系数生效完成! update count:" + count);
//    }
//
//}
